<template>

<div>
  <el-row>
    <mu-appbar title="授权记录" style="background-color:#409EFF">
      <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'AuthMenu' }"/>
    </mu-appbar>
  </el-row>
  <el-row>
    <el-col :span="12">
    </el-col>
    <el-col :span="12">
      <i class="el-icon-arrow-down" style="float:right" @click="handleTools"></i>
    </el-col>
  </el-row>
  <div class= "tools" v-show="tools">
    <el-row>
      <el-col :xs="6" :sm="4" :md="3" :lg="3">
        玩家ID
      </el-col>
      <el-col :xs="18" :sm="20" :md="21" :lg="21">
        <el-input v-model="condition.uid" size="mini" @blur="handleFind"></el-input>
      </el-col>
    </el-row>
  </div>

  <el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="uid"
        label="玩家ID">
      </el-table-column>
      <el-table-column
        prop="binderUid"
        label="上级ID">
      </el-table-column>
      <el-table-column
        prop="realName"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="wechat"
        label="微信号">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="手机号">
      </el-table-column>
      <el-table-column
        prop="checkStatusName"
        label="状态">
      </el-table-column>
      <el-table-column
        prop="subTime"
        label="申请时间">
      </el-table-column>
      <el-table-column label="操作" v-if="this.isAdmin">
        <template slot-scope="scope">
          <el-row>
              <el-col :xs="24" :sm="12" :md="12" :lg="12">
                <el-button type="primary" size="mini" v-if="scope.row.checkStatus === 2">转为同意</el-button>
                <el-button disabled type="primary" size="mini" v-if="scope.row.checkStatus === 3">转为同意</el-button>
              </el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
  </el-row>

  <el-row>
    <center>
      <el-pagination
        small
        layout="prev, pager, next"
        :total="condition.total"
        :page-size="condition.pageSize"
        :current-page="condition.currentPage"
        @current-change="handleCurrentChange">
      </el-pagination>
    </center>
  </el-row>
</div>

</template>

<style scoped>
  .el-row {
    margin-bottom: 16px;
  }
  .el-col {
    margin-bottom: 8px;
  }
</style>

<script>
  import moment from 'moment'
  export default {
    data () {
      return {
        tools: true,
        tableData: [],
        condition: {
          startDay: this.$time.getDateBefore(new Date(), -3),
          endDay: this.$time.getDateBefore(new Date(), 0),
          uid: '',
          currentPage: 1,
          pageSize: 10,
          total: 0,
          account: sessionStorage.getItem('account')
        },
        options: [
          {
            value: '0',
            label: '全部'
          },
          {
            value: '1',
            label: '审核中'
          },
          {
            value: '2',
            label: '已拒绝'
          },
          {
            value: '3',
            label: '已通过'
          }
        ],
        isAdmin: false
      }
    },
    methods: {
      handleTools () {
        if (this.tools) {
          this.tools = false
        } else {
          this.tools = true
        }
      },
      handleFind () {
        let that = this
        if (this.condition.uid === '' || this.condition.uid.length === 0) {
          this.condition.uid = -1
        }
        this.$axios({
          method: 'get',
          url: '/api/AgentService.getAgentApplyed',
          params: this.condition
        })
        .then(function (resp) {
          that.condition.uid = ''
          for (let item in resp.data.data) {
            resp.data.data[item].subTime = moment.utc(resp.data.data[item].subTime).zone(-8).format('YYYY-MM-DD HH:mm:ss')
          }
          that.tableData = resp.data.data
          that.condition.total = resp.data.page.total
        })
      },
      init () {
        this.handleFind()
      },
      handleCurrentChange (val) {
        this.condition.currentPage = val
        this.handleFind()
      }
    },
    mounted () {
      if (sessionStorage.getItem('role') === 'admin') {
        this.isAdmin = true
      }
      this.init()
    }
  }
</script>
